#  Copyright (c) 2020 - ~, WANGXI
#  
#  GRAMMA PROCEDURE TEST TCL FILE
#  Used in NS-2 simulator
#  Clone from https://gitee.com/WangXi_Chn/ns2_modulelib
#  Note in https://www.yuque.com/wangxi_chn/kozrfl
#  
#  Change Logs:
#  Date           Author       Notes			Mail
#  2020-12-05     WangXi   	   first version	WangXi_Chn@foxmail.com

proc sum_proc {a b} {
    return [expr {$a + $b}]
}

proc magnitude {num} {
    if {$num > 0} {
        return $num
    }
    set num [expr {$num*(-1)}]
    return $num
}

set num1 12
set num2 14
set sum [sum_proc $num1 $num2]

puts "The sum is $sum"
puts "The magnitude of 3 is [magnitude 3]"
puts "The magnitude of -2 is [magnitude -2]"

#---------------------------
proc dumb_proc {} {
    set myvar 4
    puts "The value of the local variable is $myvar"
    global myglobalvar
    puts "The value of the global variable is $myglobalvar"
}

set myglobalvar 79
dumb_proc

#---------------------------
proc test {} {
    set a 43
    set b 27
    set c [expr {$a+$b}]
    set d [expr {[expr {$a-$b}]*$c}]
    for {set k 0} {$k < 10} {incr k} {
        if {$k<5} {
            puts "k < 5,pow = [expr pow($d,$k)]"
        } else {
            puts "k >= 5,mod = [expr $d % $k]"
        }
    }
}

test 


#/************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
